using CCWin;
using ERPWinFormWork.Sales.DTO;
using ERPWinFormWork.Sales.DTO.Output;
using ERPWinFormWork.Sales.ErrorCode;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ERPWinFormWork.Sales
{
    public partial class DiscountDetailsForm : Form
    {
        private ApiClient _apiClient;
        private int discountId;

        public DiscountDetailsForm(int id)
        {
            InitializeComponent();
            _apiClient = new ApiClient(AppConfig.ApiBaseUrl);
            discountId = id;
            LoadData();
        }

        private async void LoadData()
        {
            var parameters = new Dictionary<string, string> { { "Id", discountId.ToString() } };
            var response = await _apiClient.GetAsync<ApiResponse<DiscountAdd>>(
                endpoint: "Sales/DiscountGetById",
                parameters: parameters
            );
            if (response != null && response.code == 200)
            {
                //var data = response.data;
                //txtDiscount_Name.Text = data.discount.Discount_Name;
                //// Assuming we need to set product name or fetch separately if needed
                //// For simplicity, assume DiscountAdd includes product details or adjust accordingly
                //// txtProductNumber.Text = ...;
                //// txtSpecification.Text = ...;
                //// txtType.Text = ...;
                //txtDiscountDescr.Text = data.discount.Discount_Descr;

                //// Populate stepwise grid
                //dgvStepwise.Rows.Clear();
                //foreach (var step in data.stepwises)
                //{
                //    dgvStepwise.Rows.Add(step.Stepwise_Condition, step.Discount);
                //}

                //// Populate repeat grid
                //dgvRepeat.Rows.Clear();
                //foreach (var rep in data.repeats)
                //{
                //    dgvRepeat.Rows.Add(rep.Repeat_Condition, rep.Discount);
                //}
            }
            else
            {
                MessageBox.Show("加载详情失败: " + (response?.msg ?? "未知错误"));
                this.Close();
            }
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // DiscountDetailsForm
            // 
            this.ClientSize = new System.Drawing.Size(1506, 632);
            this.Name = "DiscountDetailsForm";
            this.ResumeLayout(false);

        }

        // Designer code would be copied and modified to remove edit capabilities
        // For brevity, assume InitializeComponent sets up read-only controls
    }
} 